package com.control;

import com.dbutil.UtilJdbc;
import com.entity.Push_work;
import com.entity.User;
import com.entity.Works;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

public class UpdateByidServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        String workName = req.getParameter("workName");
        String date = req.getParameter("pushDate");
        String work = req.getParameter("work");


        HttpSession session = req.getSession();
        User user= (User) session.getAttribute("user");
        String name = user.getUser_name().toString();
        UtilJdbc utilJdbc = new UtilJdbc();
        Works works=utilJdbc.findWorkByNameDate(name,date);
        if (works==null) {

            req.setAttribute("workName",workName);
            req.setAttribute("work",work);
            req.setAttribute("date",date);
            req.getRequestDispatcher("/LoginPag/doWork.jsp").forward(req,resp);
        }else {
            //resp.sendRedirect("/view_works.jsp?ses=yes");

            req.getRequestDispatcher("/LoginPag/DoWorkSuccess.jsp").forward(req,resp);
        }


    }
}
